<template>
	<view class="content">
		<!-- 设置提现验证码 提现密码输入-->
		<!-- 导航栏 -->
		<!-- <free-nav-bar showBack title="设置提现密码"></free-nav-bar> -->
		<view class="title" @click="type++">{{title}}</view>
		<view class="msg">{{msg}}</view>
		<one-input v-model="test" type="box" :maxlength ='maxlength' name="one" @finish="finishedOne"  ></one-input>
		<view class="btn" @click="again" v-show="againMsg">{{end}}</view>
			
		
	</view>
</template>

<script>
	
	import oneInput from '@/components/uni-ui/myp-one/one.vue'
	import {senMsg,checkSms} from '@/apis/login/index.js'
	import { updatePassword } from '@/apis/wallet/index.js'
	// import freeNavBar from '@/components/common/nav-bar/free-nav-bar.vue';
	export default {
		components: {
			oneInput,
			// freeNavBar
		},
		data() {
			return {
				maxlength:4,//输入框长度 6位设置密码 4验证码
				type:1,//当前需要的操作  1发送验证码 2第一次输入密码 2第二次输入密码
				test: '',//完整输入内容
				title:'',//第一行文字
				msg:'短信已发送',//第二行
				mobile:'',
				end:'重新获取',
				againMsg:false,//判断重新发送字样是否展示
				firstPassword:'',
				secondPassword:'',
				
			}
		},
		onLoad(option) {
			if(option.type){
				this.type = option.type
				this.mobile = this.$store.state.userInfo.mobile
				if(option.type == 1){
					this.title = '已发送验证码至'+this.mobile
					this.getCode()
				}else if(option.type == 2){
					this.maxlength = 6
					this.title='设置密码'
					this.test=''
					this.msg ='请设置6位提现密码，用于提现验证'
					this.againMsg = false
					uni.setNavigationBarTitle({
					    title: '设置支付密码'
					});
				}
			}
		},
		watch:{

		},
		methods: {
			//发送验证码
			async getCode(){
				console.log(1)
				let data ={
					mobile:this.mobile,
					type:7
				}         
				let res =await senMsg(data)
				console.log(res,'获取验证码')
					if(res.success){
						plus.nativeUI.toast('发送成功！')
						// uni.showToast({
						// 	icon:'none',
						// 	title:'发送成功！'
						// })
					}
					// else{
					// 	plus.nativeUI.toast('验证码发送失败！')
					// 	uni.navigateBack({
					// 		delta:1
					// 	})
					// }
						   
			},
			again(){
				this.getCode()
			},
			//输入结束输出输入结果
			async finishedOne() {
				if(this.type==1){
					let data={
						code:this.test,
						mobile:this.phone,
						type:7,
					}
					let res=await checkSms(data)
					if(res.success){
						this.type = 2
						this.maxlength = 6
						this.title='设置密码'
						this.test=''
						this.msg ='请设置6位提现密码，用于提现验证'
						this.againMsg = false
						uni.setNavigationBarTitle({
						    title: '设置支付密码'
						});
						plus.nativeUI.toast('验证成功！请输入密码')
						// uni.showToast({
						// 	icon:'none',
						// 	title:'验证成功！请输入密码',
						// })
					}else{
						this.againMsg = true
						this.test=''
					}
				}else if(this.type == 2){
					this.firstPassword=this.test
					this.type =3
					this.title='确认密码'
					this.msg ='请再次输入提现密码'
					this.test=''
				}else if(this.type == 3){
					this.secondPassword=this.test
					let data ={
						password1:this.firstPassword,
						password2:this.secondPassword
					}
					let res =await updatePassword(data)
					if(res.success){
						plus.nativeUI.toast('设置成功！')
						// uni.showToast({
						// 	icon:'success',
						// 	title:'设置成功！'
						// })
						setTimeout(()=>{
							uni.navigateBack({
								delta:2
							})
						},300)
						
					}
				}
				
			},
		}
	}
</script>

<style  lang="scss" scoped>
	.content{
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
	}
	.title{
		margin-top: 240rpx;
		// width: 128rpx;
		height: 44rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.87);
		line-height: 44rpx;
		margin-left: 118rpx;
		margin-bottom: 32rpx;
	}
	.msg{
		// width: 438rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.38);
		line-height: 40rpx;
		margin-left: 118rpx;
		margin-bottom: 120rpx;
	}
	::v-deep .code-box{
		// position: absolute;
		// top: 100rpx;
	}
	.btn{
		width: 218rpx;
		height: 90rpx;
		// background: #00C777;
		margin: 0 auto;
		margin-top: 42rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #3C8EFF;
		line-height: 90rpx;
		text-align: center;
	}
</style>
